package com.machuxin.course.patterns.single;

import java.io.Serializable;

/**
 * 懒汉式
 */
public class Singleton4 implements Serializable {

    private static class Holder{
        private static final Singleton4 singleton3 = new Singleton4();
    }

    /**
     * 私有化构造方法
     */
    private Singleton4() {
        if(Holder.singleton3 != null){
            throw new RuntimeException("不允许创建多个实例");
        }
    }

    public static final Singleton4 getInstance() {
        return Holder.singleton3;
    }

    private Object readResolve(){
        return Holder.singleton3;
    }

}
